home *** CD-ROM | disk | FTP | other *** search
- Path: munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
- Newsgroups: comp.lang.c++
- Subject: Re: Bug or Feature? const int variables do not export in gcc 2.7.0
- Date: 12 Feb 1996 09:11:41 GMT
- Organization: Comp Sci, University of Melbourne
- Message-ID: <4fn08e$oh0@mulga.cs.mu.OZ.AU>
- References: <4fdlee$bpf@netlab.cs.rpi.edu>
- NNTP-Posting-Host: munta.cs.mu.oz.au
-
- ivo.welch@AGSM.UCLA.EDU (Ivo Welch) writes:
-
- >On a NextStep/FIP system w/ gcc 2.7.0:
- >
- >File try2.cc:
- > int ex1=2;
- >
- >File try1.cc:
- > extern "C" {
- > #include <stdio.h>
- > }
- >
- > int main() {
- > extern int ex1; printf("Extern = %d\n", ex1); return 0; }
- >
- >works, but if I replace "int" with "const int" in both situations, the
- >linker complains that ex1 is not defined. NOTE that it works with "const"
- >in gcc if instead of C++ I switch to plain C.
-
- GNU C/C++'s behaviour is correct. In C++ declaring a variable as
- `const' also implies that it has static linkage. This is a difference
- between C and C++. I guess you could call it a feature, although it is
- a somewhat surprising special case.
-
- --
- Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
- fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
-